package com.bdzl.admin.controller.sys;

import java.util.List;
import java.util.Map;

import com.bdzl.pub.controller.BaseController;
import org.springframework.stereotype.Controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.bdzl.pub.entity.sys.LogDO;
import com.bdzl.admin.service.sys.LogService;
import com.bdzl.pub.util.param.PageUtils;
import com.bdzl.pub.util.param.Query;
import com.bdzl.pub.util.param.R;

/**
 * 系统日志表 
 * 
 * @author yangyicai
 * @email yangyicai@foxmail.com
 * @date 2021-03-23 13:59:22
 */
 
@Controller
@RequestMapping("/bdzl/log")
public class LogController extends BaseController {
	@Autowired
	private LogService logService;
	
	@GetMapping()
	String Log(){
	    return "bdzl/log/log";
	}
	
	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<LogDO> logList = logService.list(query);
		int total = logService.count(query);
		PageUtils pageUtils = new PageUtils(logList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	String add(){
	    return "bdzl/log/add";
	}

	@PostMapping("/edit")
	@ResponseBody
	LogDO edit(@RequestBody LogDO log){
		log = logService.get(log.getLogId());
	    return log;
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save( LogDO log){
		if(logService.save(log)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update( LogDO log){
		logService.update(log);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove(@RequestBody LogDO log){
		if(logService.remove(log.getLogId())>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	public R remove(@RequestParam("ids[]") Integer[] logIds){
		logService.batchRemove(logIds);
		return R.ok();
	}
	
}
